<?PHP
 session_start();
 include("admin/include/db.php");
 include("includes/function.php");


  if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'forgot_password'){
	
	$user_email 	= mysql_real_escape_string($_REQUEST['user_email']);
    
	$sqlCategory = mysql_query("SELECT * FROM software_user WHERE email = '$user_email'");
	$resCategory = mysql_fetch_array($sqlCategory); 
	$emailAddress= $resCategory["email"]; 
	
	$randomNumber= generatePassword(); 

		
	if($emailAddress != '')
	{
		mysql_query("UPDATE software_user SET password = '".$randomNumber."' where email = '$user_email'");
		
		$to		 =	$user_email;
		$to      =  $to.',humzarafaqat@hotmail.com,consultjai@gmail.com';
		$from 	 = "nospam@softwarecoursesonline.com";
		$subject = "Your forgot password is retrieved at softwarecoursesonline.com!";
		
		$emailMessage = '
						<style type="text/css">
							.text {font-family: Arial, Helvetica, sans-serif; font-size: 12px; }						
						</style>
						<table width="100%" cellpadding="2" cellspacing="2" class="text">																	
							<tr>
								<td colspan="2" align="left">&nbsp;</td>
							</tr>
							<tr>
								<td colspan="2" align="left">Forgot your password! </td>
							</tr>
							<tr>
								<td colspan="2" align="left" style="padding-top:10px">Please check your password in the give below</td>
							</tr>
							<tr>
								<td colspan="2" align="left" style="padding-top:10px">Email: '.$emailAddress.'</td>
							</tr>
							<tr>
								<td colspan="2" align="left" style="padding-top:10px">Password: '.$randomNumber.'</td>
							</tr>
							<tr>
								<td colspan="2" align="left" style="padding-top:10px">&nbsp;</td>
							</tr>
						</table>';
						
		emailFormat($to , FROM, $subject , $emailMessage);
		header("location:forgot_password.php?msg=1");
		exit();	
		
	}
	else
		header("location:forgot_password.php?msg=2");
	exit();		
 }
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=TITLE_WEBSITE?></title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<script>s
function register_validation(){
	
	var message = '';
	var emailReg	  = document.getElementById("user_email").value;
	
	if(emailReg == ''){
		message += 'Please enter email address \n';	
	}
	
	if(emailReg != ""){
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    	var address = emailReg;
    	if(reg.test(address) == false) {
 			message += 'Please enter valid email address\n';
      	}
	}
	
	if(message != ""){
		alert(message);
		return false;	
	}
}


</script>
<body>
<center>
<div style="background:#179cc1; height:3px">&nbsp;</div>
<div style="width:990px;" align="center">
		<div id="header">
		<?php
    		include("includes/header.php");
   		?>
        </div>
    <div style="margin-top:20px;">
    	<form id="form_login" name="form_login" method="post" onsubmit="return login_validation()" >
    	<?php
		$msg = $_REQUEST['msg'];
        if($msg != "")
		{
			if($msg == 1){
				$showMessage = 'Your password has been changes successfuly,Please check your email address';
				$clsMessage = 'clsSuccess';	
			}else if($msg == 2){
				$showMessage = 'Sorry,Please check requested email is not exist';
				$clsMessage = 'clsError';
			}
		?>
        <div align="left" class="<?=$clsMessage?>" style="margin-bottom:10px" >
           &nbsp; 	 <?=$showMessage?>
        </div>
        <?php
		}
		?>
    	</form>
        <form id="form_register" name="form_register" method="post" onsubmit="return register_validation()" >
        <div style="float:left; width:100%;" >
        	<div align="left" >
            	<span class="headingOrange" ><strong>Forgot Password</strong></span>
            </div>
            <div class="text1"  align="left" style=" padding-top:18px;">
         		 <div  >	
                    <div style="float:left; width:40%;" class="text" align="center" >Email:</div>
                    <div style="float:left; width:60%" ><input type="text" id="user_email" class="textBox" name="user_email" value="" maxlength="30"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
               
                 <div style="margin-top:10px;" align="center">	
                 	<input type="hidden" id="action" name="action" value="forgot_password"  />
                   	<input type="submit" class="button" value="Forgot Password"  />
                </div>
                 
            </div>
        </div>
        </form>
      <div style="clear:both"></div>
    </div>
    
    <div style="margin-top:23px; margin-bottom:21px" align="center" >
    	<?php
									$sqlAdvertise = mysql_query("SELECT * FROM software_advertise 
																	WHERE 
																		banner_status = 'Y' AND banner = 2
																		ORDER BY RAND()
																		");
									$resAdvertise = mysql_fetch_array($sqlAdvertise);
							
									$imgPath  = 'admin/upload_images/'.$resAdvertise["banner_image"];
									
								?>
								<a href="http://<?=$resAdvertise["banner_url"]?>" target="_blank" ><img border="0" src="<?=$imgPath?>"  width="729" height="86" /></a>
    </div>
   </div>
   <div id="footer">
  		<?php include("includes/footer.php")?>
   </div>
</div>
	</div>
</center>
</body>
</html>
